home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Topik / Topik - Disk 24 - Productivity (19xx)(Topik Public Domain)(PD)[WB].zip / Topik - Disk 24 - Productivity (19xx)(Topik Public Domain)(PD)[WB].adf / Calendar / curses.c < prev    next >
C/C++ Source or Header  |  1990-01-31  |  4KB  |  279 lines

  1. /*  curses.c */
  2. #include <ctype.h>
  3.  
  4. /* small curses 
  5.     Bob Leivian -- some of the curses routines are here
  6.     add to them as you see fit -- the basic I/O routines are from
  7.     the micro EMACS routines from FISH disk # 23
  8.  
  9.     Bob Leivian
  10.     2702 W. Curry
  11.     Chandler Az 85224 
  12.     602-820-6859   mot!dover!leivian
  13. */
  14.  
  15. /*
  16.  * Name:    MicroEMACS
  17.  *        AmigaDOS terminal I/O
  18.  * Version:    31
  19.  * Compiler:    Manx Aztec C
  20.  * Created:    19-Apr-86 ...!ihnp4!seismo!ut-sally!ut-ngp!mic
  21.  */
  22. #include    <libraries/dos.h>
  23. #include    <libraries/dosextens.h>
  24. #undef TRUE
  25. #undef FALSE
  26.  
  27. #define    NIBUF    128        /* Probably excessive.        */
  28. #define    NOBUF    512        /* Not too big for 750/730.    */
  29.  
  30. struct    FileHandle    *tty;
  31. struct    FileHandle    *Open();
  32. char    obuf[NOBUF];    /* Output buffer        */
  33. int    nobuf;                /* # of bytes in above        */
  34. char    ibuf[NIBUF];    /* Input buffer            */
  35. int    nibuf;                /* # of bytes in above        */
  36. int    nrow;                /* Terminal size, rows.        */
  37. int    ncol;                /* Terminal size, columns.    */
  38.  
  39. #if    MANX
  40. extern    int    Enable_Abort;
  41. #endif
  42. extern char version[];
  43.  
  44. /*
  45.  * This routine gets called once, to set up the
  46.  * terminal channel.
  47.  */
  48. ttopen()
  49. {
  50.     char WindowName[80];
  51.     
  52.     nrow = 23;
  53.     ncol = 77;
  54.     nobuf = nibuf = 0;
  55. #if    MANX
  56.     Enable_Abort = 0;    /* Disable ^C during file I/O */
  57. #endif
  58.     strcpy(WindowName,"RAW:1/1/639/199/");
  59.     strcat(WindowName, version);
  60.     tty = Open(WindowName, MODE_NEWFILE);
  61.     if (tty == (struct FileHandle *) 0) {
  62.         printf("Can't open window!\n");
  63.         exit(200);
  64.     }
  65. }
  66.  
  67. /*
  68.  * This function gets called just
  69.  * before we go back home to the command interpreter.
  70.  * On the Amiga it closes up the virtual terminal window.
  71.  */
  72. ttclose()
  73. {
  74.     if (tty != (struct FileHandle *) 0L) {
  75.         ttflush();
  76.         Close(tty);
  77.     }
  78.     tty = /*(struct FileHandle *)*/ NULL;
  79. #if    MANX
  80.     Enable_Abort = 1;
  81. #endif
  82. }
  83.  
  84. /*
  85.  * Write a character to the display.
  86.  * On the Amiga, terminal output is buffered, and
  87.  * we just put the characters in the big array,
  88.  * after cheching for overflow.
  89.  */
  90. ttputc(c)
  91. {
  92.     if (nobuf >= NOBUF)
  93.         ttflush();
  94.     obuf[nobuf++] = c;
  95. }
  96.  
  97. /*
  98.  * This function does the real work of
  99.  * flushing out buffered I/O on the Amiga. All
  100.  * we do is blast out the block with a write call.
  101.  */
  102. ttflush()
  103. {
  104.     if (nobuf > 0) {
  105.         Write(tty,obuf,(long) nobuf);
  106.         nobuf = 0;
  107.     }
  108. }
  109.  
  110. /*
  111.  * Read a character from the terminal,
  112.  * performing no editing and doing conditional echo 
  113.  */
  114. int do_echo = 1; /* echo flag */
  115.  
  116. ttgetc()
  117. {
  118.     unsigned char c, ignore;    /* must be unsigned! */
  119.  
  120.     ttflush();
  121.  
  122.     Read(tty,&c,1L);
  123.     if (c == '\x9b') {
  124.         Read(tty, &c, 1L);
  125.  
  126.         /* was it a function key  */
  127.         if (isdigit(c))
  128.             Read(tty, &ignore, 1L);
  129.  
  130.         /* return the char with top bit set */
  131.         c |= 0x80;
  132.     } else 
  133.         if (do_echo) 
  134.             ttputc(c);
  135.  
  136.     return ((int) c);
  137. }
  138.  
  139. /*
  140.  * Write a string to the terminal 
  141.  */
  142. ttputs(s)
  143. char *s;
  144. {
  145.     while(*s) ttputc(*s++);
  146.     ttflush();
  147. }
  148.  
  149. char scr_buf[24][80];
  150. int scr_row, scr_col;
  151.  
  152.  
  153. /* this is some the curses routines */
  154.  
  155. standout()
  156. {
  157.     /* standout (in this case by reverse vidio) */
  158.     ttputs("\x9b7m");
  159. }
  160.  
  161. standend()
  162. {
  163.     ttputs("\x9bm");
  164. }
  165.  
  166. move(x,y)
  167. {
  168.     char buf[32];
  169.  
  170.  
  171.     sprintf(buf, "\x9b%d;%dH", x+1, y+1);
  172.     ttputs(buf);
  173.     ttflush();
  174.  
  175.     scr_row = x;
  176.     scr_col = y;
  177. }
  178.  
  179. addstr(s)
  180. char *s;
  181. {
  182.     while(*s) {
  183.         ttputc(*s);
  184.         scr_buf[scr_row][scr_col++] = *s++;
  185.         if(scr_col >= 78)
  186.             break;
  187.     }
  188.     ttflush();
  189. }
  190.  
  191. mvaddstr(x,y,s)
  192. int x,y;
  193. char *s;
  194. {
  195.     move(x,y);
  196.     addstr(s);
  197. }
  198.  
  199. addch(c)
  200. char c;
  201. {
  202.     ttputc(c);
  203.     scr_buf[scr_row][scr_col] = c;
  204.     scr_col++;
  205. }
  206.  
  207. mvaddch(x,y,c)
  208. int x,y;
  209. char c;
  210. {
  211.     move(x, y);
  212.     addch(c);
  213. }
  214.  
  215. inch()
  216. {
  217.     return scr_buf[scr_row] [scr_col];
  218. }
  219.  
  220. refresh()
  221. {
  222. }
  223.  
  224. clrtobot()
  225. {
  226.     int i,j;
  227.  
  228.     ttputs("\x9bJ");
  229.     for (j = scr_col; j < 79; j++)
  230.         scr_buf[scr_row][j] = ' ';
  231.     for (i = scr_row++; i < 23; i++)
  232.         for (j = 0; j < 79; j++)
  233.             scr_buf[i][j] = ' ';
  234. }
  235.  
  236. clrtoeol()
  237. {
  238.     int i;
  239.  
  240.     ttputs("\x9bK");
  241.     for (i = scr_col; i < 79; i++)
  242.         scr_buf[scr_row][i] = ' ';
  243. }
  244.  
  245. clear()
  246. {
  247.     int i,j;
  248.  
  249.     ttputc('\f');
  250.     for (i = 0; i < 23; i++)
  251.         for (j = 0; j < 79; j++)
  252.             scr_buf[i][j] = ' ';
  253. }
  254.  
  255. initscr()
  256. {
  257.     ttopen();
  258.     clear();
  259. }
  260.  
  261. crmode()
  262. {
  263. }
  264.  
  265. noecho()
  266. {
  267.     do_echo = 0;
  268. }
  269.  
  270. echo()
  271. {
  272.     do_echo = 1;
  273. }
  274.  
  275. endwin()
  276. {
  277.     ttclose();
  278. }
  279.